<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-card>
      <!-- 文本框 -->
      <el-input placeholder="请输入内容" clearable style="width: 400px">
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <!-- 主体表单区域 -->
      <el-table :data="orderList" style="width: 100%" border stripe>
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="400px">
        </el-table-column>
        <el-table-column prop="order_price" label="价格"> </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.user_id !== 1"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column prop="create_time" label="下单时间" width="300px">
          <template slot-scope="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <!-- 修改 -->
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="addDialogOrder(scope)"
            ></el-button>
            <!-- 地图 -->
            <el-button
              type="danger"
              icon="el-icon-location-outline"
              size="mini"
              @click="showProgressBox"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 3, 9, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 修改区域 -->
    <el-dialog
      title="修改区域"
      @close="addDialogColes"
      :visible.sync="addDialogVisible"
      width="50%"
    >
      <!-- 表单数据 -->
      <el-form
        :model="addressForm"
        :rules="addressFormRules"
        ref="addressFormRef"
        label-width="100px"
      >
        <el-form-item label="省市区" prop="address1">
          <el-cascader
            :options="cityData"
            v-model="addressForm.address1"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="addressForm.address2"></el-input>
        </el-form-item>
      </el-form>
      <!-- 底部确认取消 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <!-- 显示物流对话框 -->
    <el-dialog title="提示" :visible.sync="addressVisible" width="50%">
      <!-- 事件线 -->
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in progressInfo"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>


      <span slot="footer" class="dialog-footer">
        <el-button @click="addressVisible = false">取 消</el-button>
        <el-button type="primary" @click="addressVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import cityData from './citydata'
import progressTest from './progressInfo.js'

export default {
  data() {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 5,
      },
      // 存放数据
      orderList: [],
      total: 0,
      addDialogVisible: false,
      addressForm: {
        address1: [],
        address2: '',
      },
      cityData,
      // 表单验证规则
      addressFormRules: {
        address1: [
          {
            required: true,
            message: '请输入省市区',
            trigger: 'blur',
          },
        ],
        address2: [
          {
            required: true,
            message: '请输入详细地址',
            trigger: 'blur',
          },
        ],
      },
      addressVisible: false,
      progressInfo:'这是一段信息',
      progressTestInfo: progressTest
    }
  },
  created() {
    this.getOrderList()
  },

  methods: {
    // 获取页面信息 渲染
    async getOrderList() {
      const { data: res } = await this.$http.get('orders', {
        params: this.queryInfo,
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单数据失败')
      }
      this.$message.success('获取订单数据成功')
      console.log(res.data)
      this.orderList = res.data.goods
      this.total = res.data.total
      console.log(this.orderList.order_number)
    },
    // 每行发生变化时候
    handleCurrentChange(pageNum) {
      this.queryInfo.pagenum = pageNum
      this.getOrderList()
    },

    // 每页发生变化时
    handleSizeChange(pageSize) {
      this.queryInfo.pagesize = pageSize
      this.getOrderList()
    },
    // 点击修改按钮
    async addDialogOrder(id) {
      console.log(id)
      const { data: res } = await this.$http.get('orders' + id)
      console.log(res.data)
      this.addDialogVisible = true
    },
    // 监听表单清空事件
    addDialogColes() {
      this.$refs.addressFormRef.resetFields()
    },
    async showProgressBox() {
      // 获取物流信息
      //展示物流进度的对话框
      this.progressInfo = this.progressTestInfo[0].data
    //   console.log(this.progressTestInfo)
      console.log(this.progressInfo[0].data)
      this.addressVisible = true
    },
  },
}
</script>

<style lang="less" scoped></style>
